﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.QcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.QcManagement.QcInspectItemVMs
{
    public partial class QcInspectItemListVM : BasePagedListVM<QcInspectItem_View, QcInspectItemSearcher>
    {
        
        protected override IEnumerable<IGridColumn<QcInspectItem_View>> InitGridHeader()
        {
            return new List<GridColumn<QcInspectItem_View>>{
                
                this.MakeGridHeader(x => x.QcInspectItem_Template).SetTitle(@Localizer["Page.模板"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_QcType).SetTitle(@Localizer["Page.检验分类"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_InspectName).SetTitle(@Localizer["Page.检验项目"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_InspectTool).SetTitle(@Localizer["Page.检测工具"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_Content).SetTitle(@Localizer["Page.检验内容"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_RefValue).SetTitle(@Localizer["Page.参考值"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.QcInspectItem_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<QcInspectItem_View> GetSearchQuery()
        {
            var query = DC.Set<QcInspectItem>()
                
                .CheckEqual(Searcher.TemplateId, x=>x.TemplateId)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.QcType, x=>x.QcType)
                .CheckContain(Searcher.InspectName, x=>x.InspectName)
                .CheckContain(Searcher.InspectTool, x=>x.InspectTool)
                .CheckContain(Searcher.Content, x=>x.Content)
                .CheckContain(Searcher.RefValue, x=>x.RefValue)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new QcInspectItem_View
                {
				    ID = x.ID,
                    
                    QcInspectItem_Template = x.Template.TenantCode,
                    QcInspectItem_ProductId = x.ProductId,
                    QcInspectItem_ProductName = x.ProductName,
                    QcInspectItem_QcType = x.QcType,
                    QcInspectItem_InspectName = x.InspectName,
                    QcInspectItem_InspectTool = x.InspectTool,
                    QcInspectItem_Content = x.Content,
                    QcInspectItem_RefValue = x.RefValue,
                    QcInspectItem_Remark = x.Remark,
                    QcInspectItem_CreateTime = x.CreateTime,
                    QcInspectItem_UpdateTime = x.UpdateTime,
                    QcInspectItem_CreateBy = x.CreateBy,
                    QcInspectItem_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class QcInspectItem_View: QcInspectItem
    {
        
        public string QcInspectItem_Template { get; set; }
        public long? QcInspectItem_ProductId { get; set; }
        public string QcInspectItem_ProductName { get; set; }
        public EquipTypeEnum? QcInspectItem_QcType { get; set; }
        public string QcInspectItem_InspectName { get; set; }
        public string QcInspectItem_InspectTool { get; set; }
        public string QcInspectItem_Content { get; set; }
        public string QcInspectItem_RefValue { get; set; }
        public string QcInspectItem_Remark { get; set; }
        public DateTime? QcInspectItem_CreateTime { get; set; }
        public DateTime? QcInspectItem_UpdateTime { get; set; }
        public string QcInspectItem_CreateBy { get; set; }
        public string QcInspectItem_UpdateBy { get; set; }

    }

}